<?php
/**
 * Huisheng 瑞声鉴权接口
 */
namespace app\common\lib;
use think\Exception;
class Huisheng
{

    /**
     * 获取token信息
     * @return false|mixed
     */
    public static function  login($api_key,$api_secret)
    {

        try{

            $url = config("config.token.url").'/auth/login';
            $post_data['api_key']  = $api_key;
            $post_data['api_secret'] = $api_secret;
            $res = \app\common\lib\CurlHandle::sendPost($url, $post_data);
            $data = json_decode($res, true);
            if($data){
                if($data['code'] == 200){
                    return  $data['data'];
                }else{
                    return false;
                }
            }else{
                return false;
            }
        } catch(\Exception $e) {
            logWrite('Huisheng/login', $e->getMessage(), __FILE__ );
            throw new Exception(config("config.describe.error"),config("config.code.error"));
        }

    }
    /**
     * 获取token信息
     * @return false|mixed
     */
    public static function getToken($token){
        try {
            $url = config("config.token.url").'/auth/tokenInfo';
            $post_data['token']  = $token;
            $res = \app\common\lib\CurlHandle::sendPost($url, $post_data);
            $data = json_decode($res, true);
            if($data){
                if($data['code'] == 200){
                    return  $data['data'];
                }else{
                    return false;
                }
            }else{
                return false;
            }
        }catch (\Exception $e){
            logWrite('getToken', $e->getMessage(), __FILE__ );
            throw new Exception(config("config.describe.error"),config("config.code.error"));
        }
    }


}
